<section class="page-hd">
    <header>
        <p class="title-description title-top">
            账号管理
        </p>
    </header>
    <hr>
</section>

<table class="table table-bordered  mb-15">
    <colgroup>
        <col width="40"/>
        <col width="120"/>
        <col width="100"/>
        <col width="100"/>
        <col width="100"/>
        <col width="100"/>
        <col width="100"/>
        <col width="100"/>
    </colgroup>
    <thead>
    <tr>
        <th>编号</th>
        <th>用户名称</th>
        <th>登录次数</th>
        <th>用户权限</th>
        <th>创建时间</th>
        <th>登录时间</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {volist name='list' id='val' key='k'}
    <tr class="cen">
        <td>{$val.userId}</td>
        <td>{$val.userName}</td>
        <td>{$val.hist}</td>
        <td>{if condition="$val.grade == 0"}超级管理员{else/}普通会员{/if}</td>
        <td>{$val.created|date="Y-m-d H:i:s",###}</td>
        <td>{$val.lastTime|date="Y-m-d H:i:s",###}</td>
        <td>{$val.state_msg}</td>
        <td>
            <a title="编辑" class="mr-5" href='{:url("detail",["id"=>$val.userId])}'>编辑</a>
            <a title="删除" class="user-del" data-id="{$val.userId}">删除</a>
        </td>
    </tr>
    {/volist}
    </tbody>
</table>

<script>
    $('body').on('click', '.user-del', function () {
        var id = $(this).attr('data-id');
        Ajax("{:url('user/del')}", {id: id});
    });
    function Ajax(url, data) {
        $.ajax({
            url: url,
            cache: false,
            dataType: 'json',
            data: data,
            type: 'post',
        }).done(function (res) {
            if(res.code == 200){
                layer.alert(res.msg,function(){
                    location.reload();
                });
            }else{
                layer.alert(res.msg);
            }
        }).fail(function (e) {
            layer.alert(e);
        });
    }
</script>